package com.example.e_comm.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.e_comm.entity.Permission;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface PermissionMapper extends BaseMapper<Permission> {
    @Select("SELECT * FROM permissions p " +
            "INNER JOIN role_permission rp ON p.id=rp.perm_id" +
            "INNER JOIN user_role ur ON rp.rple_id = ur.role_id" +
    "WHERE p.deleted = 0 AND ur.user_id=#{userId}")
    List<Permission> getPermissionsByUserId(@Param("userId") Long userId);
    @Select("SELECT * FROM permissions p " +
            "INNER JOIN role_permission rp ON p.id=rp.perm_id"+
            "WHERE rp.rple_id = #{roleId} AND p.deleted = 0")
    List<Permission> getPermissionsByRoleId(@Param("roleId") Long roleId);
}